import { Component, OnInit } from '@angular/core';
import { LocalStorageService } from 'src/app/services/local-storage-v2/local-storage.service';
import { NzIconService } from 'ng-zorro-antd/icon';

@Component({
  selector: 'app-side-menu',
  templateUrl: './side-menu.component.html',
  styleUrls: ['./side-menu.component.css']
})
export class SideMenuComponent implements OnInit {
  selected: { [key: string]: boolean } = {};

  constructor(
    private localStorage: LocalStorageService,
    private iconService: NzIconService
  ) {
    this.selected = this.localStorage.get('menu.selected', {
      待选课程: true,
      已选课程: false
    });

    this.iconService.fetchFromIconfont({
      scriptUrl: 'https://at.alicdn.com/t/font_1492457_3dkh15nyc82.js'
    });
  }

  ngOnInit() {}

  private unselectAll() {
    for (const key in this.selected) {
      if (this.selected.hasOwnProperty(key)) {
        this.selected[key] = false;
      }
    }
  }

  saveMenuSelections(item: string) {
    this.unselectAll();
    this.selected[item] = true;
    this.localStorage.set('menu.selected', this.selected);
  }
}
